class ForumController < ApplicationController
  def index
    @forums = Forum.all
  end

  def forum
    @forum = Forum.find(params[:id])
    @topics = @forum.topics

    @new_topic = Topic.new
    @new_topic.forum = @forum
    @new_topic.user = current_user
  end

  def topic
    @topic = Topic.find(params[:id])
    @replays = @topic.replies

    @new_reply = Reply.new
    @new_reply.topic = @topic
    @new_reply.user = current_user
  end

  def post
    if params[:mode] == "reply"
      @reply = Reply.new(params[:reply])

      if @reply.save
        redirect_to :action => :topic, :id => @reply.topic.id
      else
        redirect_to :action => :topic, :id => @reply.topic.id, :notice => "Cann't create new reply"
      end
    elsif params[:mode] == "topic"
      @topic = Topic.new(params[:topic])

      if @topic.save
        redirect_to :action => :forum, :id => @topic.forum.id
      else
        redirect_to :action => :forum, :id => @topic.forum.id, :notice => "Cann't create new topic"
      end
    end
  end

  def after_post

  end

end
